package com.baizhi.controller;

import com.baizhi.entity.Manager;
import com.baizhi.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("manager")
public class ManagerController {
    @Autowired
    private ManagerService managerService;

    @RequestMapping("login")
    @ResponseBody
    public Map login(String username, String password, String validatecode, HttpSession session){
        Map map = new HashMap();
        boolean flag = false;
        String realCode = (String) session.getAttribute("validatecode");
        System.out.println(realCode);
        /*if(realCode!=null && realCode.equals(validatecode)){
            //验证码正确
        }*/
        boolean login = managerService.login(username, password);
        if(login){
            Manager manager = managerService.selectByName(username);
            session.setAttribute("login",manager);
            flag = true;
        }
        map.put("flag",flag);
        return map;
    }
}
